﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.Persistent;
using Jumpton.SFA.Server.Entity;
using com.SFA.Server.Entity;
using System.Data;

namespace Jumpton.SFA.Server.BusinessRule.MasterData
{
    public class WareHouseManager:BusinessLogic
    {
        public WAREHOUSE Load(int ID)
        {
            return (WAREHOUSE)ObjectRow.Load(typeof(WAREHOUSE), string.Format("this.ID={0}", ID));
        }

        public WAREHOUSE LoadID(string Code)
        {
            return (WAREHOUSE)ObjectRow.Load(typeof(WAREHOUSE), string.Format("Code='{0}'", Code));
        }

        public WAREHOUSE LoadID(string Code,decimal domainid,decimal id)
        {
            return (WAREHOUSE)ObjectRow.Load(typeof(WAREHOUSE), string.Format("Code='{0}' and this.DOMAINID='{1}' and this.ID <> {2}", Code,domainid,id));
        }

        public static ObjectTable GetWareHouse(decimal domainid)
        {
            return new ObjectTable(typeof(WAREHOUSE), "this.DOMAINID='" + domainid + "'");
        }

        /// <summary>
        /// 保存仓库信息
        /// </summary>
        /// <param name="ShipFrom"></param>
        /// <returns></returns>
        public bool Save(WAREHOUSE warehouse)
        {
            try
            {
                if (warehouse != null)
                {
                    //判断是否存在
                    if (LoadID(warehouse.CODE, warehouse.DOMAINID, warehouse.ID) != null)
                    {
                        throw new Exception("代码已存在");
                    }


                    warehouse.Save();
                }
                return true;
            }
            catch (Exception ex)
            {
                this.message = ex.Message;
                throw ex;
            }
        }
    }
}
